dnl -*- mode: Autoconf; -*-

dnl -----------------------------------------------------------------------------------------
dnl pthreads
dnl -----------------------------------------------------------------------------------------

AC_MSG_NOTICE([................................................................................])
AC_MSG_NOTICE([CHECKING FOR PTHREADS])
AC_MSG_NOTICE([................................................................................])

AC_LANG(C)

ACX_PTHREAD(tr_PTHREAD=yes, tr_PTHREAD=no)

if test "x$tr_PTHREAD" = xno;  then
  AC_MSG_ERROR([please install the pthread library])
fi

CFLAGS="${CFLAGS} ${PTHREAD_CFLAGS}"
CXXFLAGS="${CXXFLAGS} ${PTHREAD_CFLAGS}"
LDFLAGS="${LDFLAGS} ${PTHREAD_CFLAGS}"
LIBS="${LIBS} ${PTHREAD_LIBS} "

AC_LANG(C++)

SAVE_LDFLAGS="$LDFLAGS"
LDFLAGS="$LDFLAGS $lt_prog_compiler_static"

AC_MSG_CHECKING([broken __cxa_guard])

AC_RUN_IFELSE([AC_LANG_PROGRAM(
  [[
#include <pthread.h>
#include <string>

    pthread_mutex_t mutex;

    class A {
      public:
        std::string& a () {
          static std::string empty;
          return empty;
        }
    };
  ]],
  [[
    pthread_mutex_init(&mutex, 0);
    A a;
    a.a();
    return 0;
  ]])],
  [tr_cv_broken_cxa_guard=no],
  [tr_cv_broken_cxa_guard=yes],
  [tr_cv_broken_cxa_guard=yes])

AC_MSG_RESULT($tr_cv_broken_cxa_guard)

LDFLAGS="$SAVE_LDFLAGS"

if test "x$tr_cv_broken_cxa_guard" = xyes;  then
  AC_DEFINE([BROKEN_CXA_GUARD], [1], [static programs have broken cxa_guard])
fi
